package cn.ilikes.tools.nosql.jpa.clients.dataSources;

import org.slf4j.Logger;

import cn.ilikes.tools.logs.Loggerfactory;
import cn.ilikes.tools.nosql.jpa.JPASQLPersistenUnitEnv;

public abstract class AbDataSource<V> extends DataSourceBaseImple implements DataSource<V> {

	private Logger logger = Loggerfactory.instance(AbDataSource.class);

	public AbDataSource(JPASQLPersistenUnitEnv persistenUnitEnv) {
		super(persistenUnitEnv);

	}

	protected abstract boolean validateOpen();

	public abstract void init() throws JPASQLDataSourceException;

	protected abstract V createDataSource();

	@Override
	public V getDataSource() {
		if (!validateOpen())
			throw new JPAHBaseDataSourceRunTimeException("this Data Source  no  open ! ");
		return createDataSource();
	}

}